//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System.Data;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity;
using EntLibContrib.Query.Configuration.Unity;
using EntLibContrib.Query.Parameters;

namespace EntLibContrib.Query.Configuration
{
	/// <summary>
	/// Type to hold the elements of a single query parameter
	/// </summary>
	[Assembler(typeof(DataSetParameterAssembler))]
	[ContainerPolicyCreator(typeof(DataSetParameterPolicyCreator))]
	public class DataSetParameterData : DataParameterData
	{
		#region Fields
		private const string columnProperty = "column";
		private const string versionProperty = "version";
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the source column.
		/// </summary>
		/// <value>The source column.</value>
		/// <remarks>Only required when using a Dataset as the source</remarks>
		[ConfigurationProperty(columnProperty, IsRequired = false)]
		public string Column
		{
			get { return (string)base[columnProperty]; }
			set { base[columnProperty] = value; }
		}

		/// <summary>
		/// Gets or sets the source version.
		/// </summary>
		/// <value>The source version.</value>
		/// <remarks>
		/// Only required when using a Dataset as the source.
		/// Versions are Current, Default, Original and Proposed.
		/// </remarks>
		[ConfigurationProperty(versionProperty, IsRequired = false)]
		public DataRowVersion Version
		{
			get { return (DataRowVersion)base[versionProperty]; }
			set { base[versionProperty] = value; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="DataSetParameterData"/> class.
		/// </summary>
		public DataSetParameterData()
		{
      this.Version = DataRowVersion.Current;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="DataSetParameterData"/> class.
		/// </summary>
		/// <param name="name">The parameter name.</param>
		/// <param name="dbType">Type of the parameter.</param>
		/// <param name="direction">The direction of the parameter relative to the DataSet.</param>
		/// <param name="column">The source column.</param>
		/// <param name="version">The source version.</param>
		public DataSetParameterData(
			string name,
			DbType dbType,
			ParameterDirection direction,
			string column,
			DataRowVersion version
			) : base(name, typeof(DataSetParameter), dbType, direction)
		{
			this.Column = column;
			this.Version = version;
		}
		#endregion
	}
}
